package Demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2024-05-24
 * Time: 20:52
 */
public class Test {
    public static void main(String[] args) {
        Animal animal = new Dog("大黄",4);
        Dog dog = (Dog) animal;
        dog.eat();
        Animal animal1 = new Cat("小白",3);
        if (animal instanceof Cat){
            //instanceof左边是对象，右边是类；当对象是右边类或子类所创建对象时，返回true；否则，返回false。
            Cat cat = (Cat) animal;
            cat.eat();
        }else {
            System.out.println("animal1 instanceof Cat not !");
        }
    }
    public static void fuc(Animal animal) {
        animal.eat();
    }
    public static void main1(String[] args) {
        Dog dog = new Dog("大黄",2);
        dog.eat();
        Cat cat = new Cat("小白",3);
        cat.eat();
        System.out.println("--------");
        fuc(dog);
        fuc(cat);
        System.out.println("--------");
        Animal animal = new Dog("大白",4);
        animal.eat();
    }
}
